﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


    public static class InnoHelperSQLServer
    {
        public static string GetStringNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return reader.IsDBNull(ordinal) ? null : reader.GetString(ordinal);
        }
        public static long GetLongNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return reader.IsDBNull(ordinal) ? 0 : reader.GetInt64(ordinal);
        }
        public static short GetShortNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return reader.IsDBNull(ordinal) ? (short)0 : reader.GetInt16(ordinal);
        }
        public static int GetIntNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return reader.IsDBNull(ordinal) ? (int)0 : reader.GetInt32(ordinal);
        }
        public static string GetDateNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return reader.IsDBNull(ordinal) ? "" : reader.GetDateTime(ordinal).ToString("dd/MM/yyyy HH:mm:ss");
        }
        public static string GetDateTimeNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return reader.IsDBNull(ordinal) ? "" : reader.GetDateTime(ordinal).ToString("dd/MM/yyyy HH:mm:ss");
        }
        public static decimal GetDecimalNullCheck(this System.Data.IDataReader reader, int ordinal)
        {
            return (byte[])reader[ordinal]; ;
        }

        public static string GetParamString(this System.Data.SqlClient.SqlCommand cmd, string name)
        {
            return Convert.ToString(cmd.Parameters[name].Value);
        }

        public static string GetParamDate(this System.Data.SqlClient.SqlCommand cmd, string name)
        {

            return Convert.ToString(((DateTime)cmd.Parameters[name].Value).ToString("dd/MM/yyyy HH:mm:ss"));

        }

        public static DateTime StringToDate(string value)
        {

            return DateTime.ParseExact(value, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

        }
        public static string Date2String(DateTime value)
        {

            return value.ToString("dd/MM/yyyy HH:mm:ss");

        }
}
